package com.zx.cloud.security;

import lombok.Data;

/**
 * @author zhaoxuan
 * @date 2022-05-26 16:59
 **/
@Data
public class ExpNode {

    public boolean value;
    public String expression;
    private ExpNode nextExpNode;


    public ExpNode(boolean value, String expression) {
        this.value = value;
        this.expression = expression;
    }

    public synchronized ExpNode add(ExpNode expNode){
        this.nextExpNode=expNode;
        return next();
    }

    public synchronized ExpNode next(){
        return nextExpNode;
    }

    public static void main(String[] args) {
        ExpNode head=new ExpNode(true,"and");
        head.add(new ExpNode(true,"and"))
                .add(new ExpNode(true,"and"))
                .add(new ExpNode(false,"or"))
                .add(new ExpNode(true,null));

        System.out.println(expression(head));


    }

    public static boolean expression(ExpNode head){
        if ("and".equals(head.expression)){
            return head.value&&expression(head.next());
        }else if ("or".equals(head.expression)){
            return head.value||expression(head.next());
        }else {
            return head.value;
        }
    }

}
